﻿using SuperMap.Data;
using SuperMap.Realspace;
using System;
using System.Collections.Generic;
using System.Data;
using WeifenLuo.WinFormsUI.Docking;
using Ycjw.PipeLine.Map.Basic.Conditions;
using Ycjw.PipeLine.Map.Basic.SuperMap;
using Ycjw.PipeLine.Map.Tools.Conditions.BGAnalysts;

namespace Ycjw.PipeLine.Map.Tools.Conditions
{
    /// <summary>
    /// 爆管分析--废弃
    /// </summary>
    public class BGAnalyst : ConditionPanel
    {
        private Sunny.UI.UIGroupBox uiGroupBox2;
        private Sunny.UI.UIButton uiButtonSelectPipeline;
        private Sunny.UI.UISymbolLabel uiSymbolLabel1;
        private Sunny.UI.UISymbolLabel uiSymbolLabel2;
        private Sunny.UI.UIComboBox uiComboBoxPointDataset;
        private Sunny.UI.UIComboBox uiComboBoxLineDataset;
        private Sunny.UI.UIComboBox uiComboBoxMode;
        private Sunny.UI.UISymbolLabel uiSymbolLabel3;
        private Sunny.UI.UISymbolLabel uiSymbolLabel4;
        private Sunny.UI.UIDoubleUpDown uiDoubleUpDownTolerance;
        private Sunny.UI.UIGroupBox uiGroupBox1;

        public List<Layer3DDataset> NetWorkDataset = new List<Layer3DDataset>();
        private Sunny.UI.UILabel uiLabelPipelineID;
        private BGAnalystsRun m_BGAnalystsRun;
        private InformationBubble m_InformationBubble;

        public BGAnalyst() : base()
        {
            ConditionPanelName = "爆管分析";
            InitializeComponent();
        }
        protected override void OnLoad(EventArgs e)
        {
            this.uiComboBoxPointDataset.DisplayMember = "Caption";
            this.uiComboBoxPointDataset.ValueMember = "Dataset";

            this.uiComboBoxLineDataset.DisplayMember = "Caption";
            this.uiComboBoxLineDataset.ValueMember = "Dataset";
            foreach (Layer3D lyr in base.Scene.Layers)
            {
                if (lyr.Type != Layer3DType.Dataset) continue;
                var lyrDataset = lyr as Layer3DDataset;
                if (lyrDataset.Dataset == null) continue;
                if (lyrDataset.Dataset.Type == SuperMap.Data.DatasetType.Point3D)
                {
                    uiComboBoxPointDataset.Items.Add(lyrDataset);
                }
                else if (lyrDataset.Dataset.Type == SuperMap.Data.DatasetType.Line3D)
                {
                    uiComboBoxLineDataset.Items.Add(lyrDataset);
                }
                else if (lyrDataset.Dataset.Type == SuperMap.Data.DatasetType.Network3D)
                {
                    NetWorkDataset.Add(lyrDataset);
                }
            }

            m_InformationBubble = new InformationBubble
            {
                Visible = false
            };
            if(this.SceneControl.Scene == null || this.SceneControl.Scene.Layers.Count < 3)
            {
                Sunny.UI.UIMessageTip.ShowWarning("当前工作空间无法进行爆管分析，请打开正确的工作空间！");
                return;
            }
            SceneOperInterface.Remove(typeof(BGAnalystsRun));
            m_BGAnalystsRun = new BGAnalystsRun(this.SceneControl,this.uiLabelPipelineID, m_InformationBubble,System.Windows.Forms.Application.OpenForms[0]);

            uiComboBoxPointDataset.SelectedIndexChanged += UiComboBoxPointDataset_SelectedIndexChanged;
            uiComboBoxLineDataset.SelectedIndexChanged += UiComboBoxLineDataset_SelectedIndexChanged;

            uiButtonSelectPipeline.Click += UiButtonSelectPipeline_Click;
        }

        private void UiButtonSelectPipeline_Click(object sender, EventArgs e)
        {
            if (!m_BGAnalystsRun.BuildNet(this.uiComboBoxMode.SelectedIndex, this.uiDoubleUpDownTolerance.Value))
            {
                Sunny.UI.UIMessageTip.ShowWarning("构建网络错误，请检查数据");
                return;
            }
            base.SceneControl.Action = SuperMap.UI.Action3D.Select;
            m_BGAnalystsRun.SelectPipeLine();
        }

        private void UiComboBoxLineDataset_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_BGAnalystsRun.SetNetLine3D((uiComboBoxLineDataset.SelectedItem as Layer3DDataset).Dataset as DatasetVector);
        }

        private void UiComboBoxPointDataset_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_BGAnalystsRun.SetNetPoint3D((uiComboBoxPointDataset.SelectedItem as Layer3DDataset).Dataset as DatasetVector);
        }

        public override bool ConditionValid()
        {
            return true;
        }

        public override void CreateResultWindow()
        {
            base.CreateResultWindow();
        }

        public override object Do(DockPanel dockPanel = null)
        {
            if (m_BGAnalystsRun == null) return null;
            if (m_BGAnalystsRun.BuildNet(this.uiComboBoxMode.SelectedIndex, this.uiDoubleUpDownTolerance.Value))
            {
                return new List<DataTable>() { m_BGAnalystsRun.DataTableResult, m_BGAnalystsRun.DataTableEdge };
            }
            else
            {
                if (m_BGAnalystsRun.DataTableErrorResult.Rows.Count > 0)
                {
                    return m_BGAnalystsRun.DataTableErrorResult;
                }
                return null;
            }
        }

        public override SortedDictionary<string, object> SetConditions()
        {
            return base.SetConditions();
        }

        public override void AfterClose()
        {
            base.AfterClose();
        }

        public override bool ShowModal()
        {
            return base.ShowModal();
        }

        private void InitializeComponent()
        {
            this.uiGroupBox1 = new Sunny.UI.UIGroupBox();
            this.uiGroupBox2 = new Sunny.UI.UIGroupBox();
            this.uiButtonSelectPipeline = new Sunny.UI.UIButton();
            this.uiSymbolLabel1 = new Sunny.UI.UISymbolLabel();
            this.uiSymbolLabel2 = new Sunny.UI.UISymbolLabel();
            this.uiComboBoxPointDataset = new Sunny.UI.UIComboBox();
            this.uiComboBoxLineDataset = new Sunny.UI.UIComboBox();
            this.uiSymbolLabel3 = new Sunny.UI.UISymbolLabel();
            this.uiComboBoxMode = new Sunny.UI.UIComboBox();
            this.uiSymbolLabel4 = new Sunny.UI.UISymbolLabel();
            this.uiDoubleUpDownTolerance = new Sunny.UI.UIDoubleUpDown();
            this.uiLabelPipelineID = new Sunny.UI.UILabel();
            this.uiGroupBox1.SuspendLayout();
            this.uiGroupBox2.SuspendLayout();
            this.SuspendLayout();
            // 
            // uiGroupBox1
            // 
            this.uiGroupBox1.Controls.Add(this.uiDoubleUpDownTolerance);
            this.uiGroupBox1.Controls.Add(this.uiComboBoxLineDataset);
            this.uiGroupBox1.Controls.Add(this.uiComboBoxMode);
            this.uiGroupBox1.Controls.Add(this.uiComboBoxPointDataset);
            this.uiGroupBox1.Controls.Add(this.uiSymbolLabel4);
            this.uiGroupBox1.Controls.Add(this.uiSymbolLabel3);
            this.uiGroupBox1.Controls.Add(this.uiSymbolLabel2);
            this.uiGroupBox1.Controls.Add(this.uiSymbolLabel1);
            this.uiGroupBox1.Dock = System.Windows.Forms.DockStyle.Top;
            this.uiGroupBox1.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBox1.Location = new System.Drawing.Point(0, 0);
            this.uiGroupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBox1.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBox1.Name = "uiGroupBox1";
            this.uiGroupBox1.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBox1.Size = new System.Drawing.Size(492, 136);
            this.uiGroupBox1.TabIndex = 0;
            this.uiGroupBox1.Text = "构建网络参数设置";
            // 
            // uiGroupBox2
            // 
            this.uiGroupBox2.Controls.Add(this.uiLabelPipelineID);
            this.uiGroupBox2.Controls.Add(this.uiButtonSelectPipeline);
            this.uiGroupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.uiGroupBox2.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBox2.Location = new System.Drawing.Point(0, 136);
            this.uiGroupBox2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBox2.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBox2.Name = "uiGroupBox2";
            this.uiGroupBox2.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBox2.Size = new System.Drawing.Size(492, 110);
            this.uiGroupBox2.TabIndex = 1;
            this.uiGroupBox2.Text = "选取管线";
            // 
            // uiButtonSelectPipeline
            // 
            this.uiButtonSelectPipeline.Cursor = System.Windows.Forms.Cursors.Hand;
            this.uiButtonSelectPipeline.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiButtonSelectPipeline.Location = new System.Drawing.Point(166, 29);
            this.uiButtonSelectPipeline.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiButtonSelectPipeline.Name = "uiButtonSelectPipeline";
            this.uiButtonSelectPipeline.Size = new System.Drawing.Size(169, 35);
            this.uiButtonSelectPipeline.TabIndex = 0;
            this.uiButtonSelectPipeline.Text = "图上选取";
            // 
            // uiSymbolLabel1
            // 
            this.uiSymbolLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiSymbolLabel1.Location = new System.Drawing.Point(3, 38);
            this.uiSymbolLabel1.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiSymbolLabel1.Name = "uiSymbolLabel1";
            this.uiSymbolLabel1.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
            this.uiSymbolLabel1.Size = new System.Drawing.Size(110, 35);
            this.uiSymbolLabel1.Symbol = 61713;
            this.uiSymbolLabel1.SymbolColor = System.Drawing.Color.Blue;
            this.uiSymbolLabel1.TabIndex = 0;
            this.uiSymbolLabel1.Text = "点数据集：";
            // 
            // uiSymbolLabel2
            // 
            this.uiSymbolLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiSymbolLabel2.Location = new System.Drawing.Point(3, 79);
            this.uiSymbolLabel2.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiSymbolLabel2.Name = "uiSymbolLabel2";
            this.uiSymbolLabel2.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
            this.uiSymbolLabel2.Size = new System.Drawing.Size(110, 35);
            this.uiSymbolLabel2.Symbol = 61734;
            this.uiSymbolLabel2.SymbolColor = System.Drawing.Color.Blue;
            this.uiSymbolLabel2.TabIndex = 0;
            this.uiSymbolLabel2.Text = "线数据集：";
            // 
            // uiComboBoxPointDataset
            // 
            this.uiComboBoxPointDataset.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
            this.uiComboBoxPointDataset.FillColor = System.Drawing.Color.White;
            this.uiComboBoxPointDataset.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiComboBoxPointDataset.Location = new System.Drawing.Point(111, 41);
            this.uiComboBoxPointDataset.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiComboBoxPointDataset.MinimumSize = new System.Drawing.Size(63, 0);
            this.uiComboBoxPointDataset.Name = "uiComboBoxPointDataset";
            this.uiComboBoxPointDataset.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
            this.uiComboBoxPointDataset.Size = new System.Drawing.Size(130, 29);
            this.uiComboBoxPointDataset.TabIndex = 1;
            this.uiComboBoxPointDataset.Text = "请选择";
            this.uiComboBoxPointDataset.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiComboBoxLineDataset
            // 
            this.uiComboBoxLineDataset.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
            this.uiComboBoxLineDataset.FillColor = System.Drawing.Color.White;
            this.uiComboBoxLineDataset.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiComboBoxLineDataset.Location = new System.Drawing.Point(111, 81);
            this.uiComboBoxLineDataset.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiComboBoxLineDataset.MinimumSize = new System.Drawing.Size(63, 0);
            this.uiComboBoxLineDataset.Name = "uiComboBoxLineDataset";
            this.uiComboBoxLineDataset.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
            this.uiComboBoxLineDataset.Size = new System.Drawing.Size(130, 29);
            this.uiComboBoxLineDataset.TabIndex = 1;
            this.uiComboBoxLineDataset.Text = "请选择";
            this.uiComboBoxLineDataset.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiSymbolLabel3
            // 
            this.uiSymbolLabel3.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiSymbolLabel3.Location = new System.Drawing.Point(248, 38);
            this.uiSymbolLabel3.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiSymbolLabel3.Name = "uiSymbolLabel3";
            this.uiSymbolLabel3.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
            this.uiSymbolLabel3.Size = new System.Drawing.Size(110, 35);
            this.uiSymbolLabel3.Symbol = 62115;
            this.uiSymbolLabel3.SymbolColor = System.Drawing.Color.Blue;
            this.uiSymbolLabel3.TabIndex = 0;
            this.uiSymbolLabel3.Text = "打断模式：";
            // 
            // uiComboBoxMode
            // 
            this.uiComboBoxMode.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList;
            this.uiComboBoxMode.FillColor = System.Drawing.Color.White;
            this.uiComboBoxMode.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiComboBoxMode.Items.AddRange(new object[] {
            "不打断",
            "点打断线",
            "线和点同时打断线"});
            this.uiComboBoxMode.Location = new System.Drawing.Point(358, 41);
            this.uiComboBoxMode.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiComboBoxMode.MinimumSize = new System.Drawing.Size(63, 0);
            this.uiComboBoxMode.Name = "uiComboBoxMode";
            this.uiComboBoxMode.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
            this.uiComboBoxMode.Size = new System.Drawing.Size(130, 29);
            this.uiComboBoxMode.TabIndex = 1;
            this.uiComboBoxMode.Text = "请选择";
            this.uiComboBoxMode.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiSymbolLabel4
            // 
            this.uiSymbolLabel4.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiSymbolLabel4.Location = new System.Drawing.Point(248, 79);
            this.uiSymbolLabel4.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiSymbolLabel4.Name = "uiSymbolLabel4";
            this.uiSymbolLabel4.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
            this.uiSymbolLabel4.Size = new System.Drawing.Size(110, 35);
            this.uiSymbolLabel4.Symbol = 61735;
            this.uiSymbolLabel4.SymbolColor = System.Drawing.Color.Blue;
            this.uiSymbolLabel4.TabIndex = 0;
            this.uiSymbolLabel4.Text = "打断容限：";
            // 
            // uiDoubleUpDownTolerance
            // 
            this.uiDoubleUpDownTolerance.Decimal = 3;
            this.uiDoubleUpDownTolerance.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiDoubleUpDownTolerance.Location = new System.Drawing.Point(358, 82);
            this.uiDoubleUpDownTolerance.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiDoubleUpDownTolerance.MinimumSize = new System.Drawing.Size(100, 0);
            this.uiDoubleUpDownTolerance.Name = "uiDoubleUpDownTolerance";
            this.uiDoubleUpDownTolerance.Size = new System.Drawing.Size(130, 29);
            this.uiDoubleUpDownTolerance.Step = 0.001D;
            this.uiDoubleUpDownTolerance.TabIndex = 2;
            this.uiDoubleUpDownTolerance.Text = "uiDoubleUpDown1";
            this.uiDoubleUpDownTolerance.Value = 0.001D;
            // 
            // uiLabelPipelineID
            // 
            this.uiLabelPipelineID.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiLabelPipelineID.Location = new System.Drawing.Point(218, 67);
            this.uiLabelPipelineID.Name = "uiLabelPipelineID";
            this.uiLabelPipelineID.Size = new System.Drawing.Size(70, 23);
            this.uiLabelPipelineID.TabIndex = 1;
            this.uiLabelPipelineID.Text = "管线ID";
            this.uiLabelPipelineID.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // BGAnalyst
            // 
            this.Controls.Add(this.uiGroupBox2);
            this.Controls.Add(this.uiGroupBox1);
            this.Name = "BGAnalyst";
            this.Size = new System.Drawing.Size(492, 246);
            this.uiGroupBox1.ResumeLayout(false);
            this.uiGroupBox2.ResumeLayout(false);
            this.ResumeLayout(false);

        }
    }
}
